/**
 * @Project Name:blog-business-service
 * @Package Name:cn.hoofungson.blog.business.service.provider.convert.user
 * @Since JDK 1.8
 */

package cn.hoofungson.blog.business.service.provider.converter.user;

import cn.hoofungson.blog.business.service.interfaces.domain.dto.user.UserDTO;
import cn.hoofungson.blog.business.service.provider.model.entity.user.UserPO;
import org.springframework.cglib.beans.BeanCopier;

/**
 * @Description: UserConverter
 * @Author 胡松 hoofungson@163.com
 * @Date 2020-03-25 8:35
 * @Version V1.0
 */
public class UserConverter {

    /**
     * DTO转PO
     *
     * @param userDTO
     * @param userPO
     **/
    public static void convert(UserDTO userDTO, UserPO userPO) {
        if (null == userDTO) {
            return;
        }
        if (null == userPO) {
            return;
        }
        BeanCopier.create(userDTO.getClass(), userPO.getClass(), false)
                .copy(userDTO, userPO, null);
    }

    /**
     * PO转DTO
     *
     * @param userPO
     * @param userDTO
     **/
    public static void convert(UserPO userPO, UserDTO userDTO) {
        if (null == userPO) {
            return;
        }
        if (null == userDTO) {
            return;
        }
        BeanCopier.create(userPO.getClass(), userDTO.getClass(), false)
                .copy(userPO, userDTO, null);
    }
}
